package com.yanqu.road.server.timer.share;

import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.ServerListMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.utils.executor.GeneralTask;

import java.util.Calendar;

public class CheckShareCodeTask extends GeneralTask {
    private long lastReloadTime;
    @Override
    public void doRun() {
        // 刷新mgr邀请码
        long now = System.currentTimeMillis();
        if (now - lastReloadTime > 10 * 60 * 1000L) {
            lastReloadTime = now;
          // ShareMgr.reloadOpenInvitedDataMap();
        }

        try{
            Calendar rightNow = Calendar.getInstance();
            int hours = rightNow.get(Calendar.HOUR_OF_DAY);
            int minute = rightNow.get(Calendar.MINUTE);
            if(hours == 18){
                int temp = (int) (GameServer.getInstance().getServerId() % 5);
                if(minute == temp){
                    ServerListMgr.reloadServerList();
                }
            }
        }catch (Exception e){
            getLOGGER().error("reload server list error:", e);
        }

        try{
            for (GamePlayer player : GamePlayerMgr.getCopyPlayerList()) {
                player.getCommandStatistics().resetAndLog();
            }
        }catch (Exception e){

        }
    }
}
